//
//  ReadCollectionCell.m
//  aMoment
//
//  Created by dllo on 15/10/5.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "ReadCollectionCell.h"
#import "AllHeaderFiles.h"

@implementation ReadCollectionCell

- (void)dealloc
{
    [_coverImageView release];
    [_titleBkgdImageView release];
    [_titleLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _coverImageView = [[UIImageView alloc] init];
//    _coverImageView.backgroundColor = [UIColor grayColor];
    _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    _coverImageView.clipsToBounds = YES;
    [self.contentView addSubview:_coverImageView];
    
    _titleBkgdImageView = [[UIImageView alloc] init];
    _titleBkgdImageView.backgroundColor = [UIColor blackColor];
    _titleBkgdImageView.alpha = .5;
    [_coverImageView addSubview:_titleBkgdImageView];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont systemFontOfSize:14.0];
    [_coverImageView addSubview:_titleLabel];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _coverImageView.frame = self.contentView.frame;
    _titleBkgdImageView.frame = CGRectMake(0, _coverImageView.Height - 20 * FIT_HEIGHT, _coverImageView.Width, 20 * FIT_HEIGHT);
    _titleLabel.frame = _titleBkgdImageView.frame;
}

#pragma mark 重写set方法
- (void)setRead:(Read *)read
{
    if (_read != read) {
        [_read release];
        _read = [read retain];
    }
    [_coverImageView setImageWithURL:[NSURL URLWithString:_read.coverimg] placeholderImage:[UIImage imageNamed:@"placeholder-image"]];
    _titleLabel.text = [NSString stringWithFormat:@"%@ %@", _read.name, _read.enname];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
